package leetcode.medium.limit100;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yaoyao1.liu@zhaopin.com.cn
 * @since 2022-11-10 15:52
 **/
public class No77 {

    public static void main(String[] args) {
        No77 no77 = new No77();
        List<List<Integer>> combine = no77.combine(4, 2);
        System.out.println(combine);
    }

    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> result = new ArrayList<>();
        deal(1, new ArrayList<>(), result, n, k);
        return result;
    }

    public void deal(int index, List<Integer> one, List<List<Integer>> result, int n, int k) {
        if (one.size() == k) {
            result.add(new ArrayList<>(one));
            return;
        }
        for (int i = index; i <= n; i++) {
            one.add(i);
            deal(i + 1, one, result, n, k);
            one.remove(one.size() - 1);
        }

    }
}
